home *** CD-ROM | disk | FTP | other *** search
- /*change this flag to 0 for the compiler, 1 for the interpreter */
- #define _INTERPRETER 1
-
- #include "Controls.h"
- #include "X_constants.h"
- #include "X_data_types.h"
- #include "X_prim_structs.h"
- #include "X_mac_structs.h"
- #include "X_sys_structs.h"
- #include "X_struct_ids.h"
- #include "X_prototypes.h"
- #include "X_macros.h"
- #include "scroll_proc.h"
-
- /* This file contains a call back for the control manager, two XPRIMs and the code */
- /* to install them in the interpreter environment. It is for use with the Scroll */
- /* Bar example class, but it also demonstrates how to use C code to do callbacks */
- /* with Prograph. */
-
- /* List of Routines:
- PGScrollAction - This is the call back that is used by the control manager.
- scroll-proc - Outputs the address of PGScrollAction.
- inst-to-addr - Outputs the address of the instance that is input.
- */
-
- #if _INTERPRETER
- ProcPtr * ct;
- #endif
-
-
- /* PGScrollAction - This is a callback routine is used by the control manager to */
- /* handle clicks in the various parts of the control. If the user */
- /* clicks in the UpButton or DownButton, this routine uses the */
- /* value of the line pixel attribute of the Prograph instance */
- /* bound to this control record. If the user clicks in the UpPage */
- /* DownPage part of the control, then this routine uses the value */
- /* of the page pixel attribute of the Prograph instance bound to */
- /* this control record. */
-
-
- pascal void PGScrollAction
- (
- ControlHandle control, /* effect control */
- Int2 part /* control part */
- )
- {
- Int4 value; /* control's value */
- Int2 min;
- Int2 max;
- C_Scroll_20_Bar *inst;
- C_integer *line;
- C_integer *page;
-
- value = GetCtlValue( control );
- min = GetCtlMin( control );
- max = GetCtlMax( control );
-
- inst = (Handle)GetCRefCon( control );
-
- line = (*inst)->line_pix;
- page = (*inst)->page_pix;
-
- switch( part )
- {
- case inUpButton:
- value -= (*line)->value;
- break;
- case inDownButton:
- value += (*line)->value;
- break;
- case inPageUp:
- value -= (*page)->value;
- break;
- case inPageDown:
- value += (*page)->value;
- break;
- default:
- return;
- }
-
- if( value < min )
- value = min;
- if( value > max )
- value = max;
-
- SetCtlValue( control, (Int2)value );
- }
-
- /* scroll-proc - This routine takes a part code as input. If the part code */
- /* indicates that the user clicked in the thumb of the control */
- /* then ZERO is returned. Otherwise, if the user clicked in any */
- /* other part of the control, this XPRIM returns the address of */
- /* the callback routine PGScrollAction. This is necessitated */
- /* by the structure of the control manager. A callback used by */
- /* the control manager when the user clicks in the thumb of a */
- /* control does not have any parameters. A callback used when the */
- /* user clicks in some other part of the control has two */
- /* parameters. Thus, when the user clicks in the thumb of the */
- /* control, this XPRIM passes out 0 so that TrackControl will take */
- /* the default action. */
-
- Nat2 U_scroll_2D_proc
- (
- C_integer *cSPart, /* Part Code */
- C_integer **cSProc /* Address of scroll proc */
- )
- {
-
- #if _INTERPRETER
- {
- Nat2 inarity, outarity;
-
- GETARITY( inarity, outarity);
-
- if( inarity != 1 && outarity != 1 )
- return PRIMERR_ARITY;
- }
- #endif
-
- if( (*cSPart)->value != 0 && (*cSPart)->value != inThumb )
- *cSProc = MakeC_integer( (Int4)(&PGScrollAction) );
- else
- *cSProc = MakeC_integer( (Int4)0 );
-
- return PCF_TRUE;
- }
-
- #if _INTERPRETER
-
- /* main loads primitives into prograph interpreter's primitive table */
-
- void main( table )
-
- ProcPtr * table; /* common table */
-
- {
- asm
- {
- move.l a4, -(sp) /* move A4 on to the stack */
- move.l a0, a4 /* move address of code resource to A4 */
- }
-
- ct = table; /* set up common table for shared functions */
-
- AddPrimitive( 1, 0x0101, PF_USER, 0, &U_scroll_2D_proc );
-
- asm { move.l (sp)+, a4 } /* move saved value back into A4 */
- }
-
- #endif
-